home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / sc3x04.exe / SCTRPATH.C < prev    next >
C/C++ Source or Header  |  1993-04-09  |  7KB  |  189 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      sctrpath.c                                            ║
  4. //   ║ abstract:    This module shows how to make 3.x system calls using  ║
  5. //   ║              the F2 Shell Interface for the Scan Bindery Object    ║
  6. //   ║              Trustee Paths API, obviously it requires the NetWare  ║
  7. //   ║              Shell.                                                ║
  8. //   ║                                                                    ║
  9. //   ║              This call may need to be made iteratively to return   ║
  10. //   ║              all of the trustee information.  For simplicity,      ║
  11. //   ║              this example only makes the call once.  To return     ║
  12. //   ║              other entries, the sequence number returned by the    ║
  13. //   ║              previous call must be passed into the next call.      ║
  14. //   ║                                                                    ║
  15. //   ║              Whatever volume name is entered must be for the       ║
  16. //   ║              default server.                                       ║
  17. //   ║                                                                    ║
  18. //   ║ environment: NetWare 3.x v3.11                                     ║
  19. //   ║              Borland C++ 3.1                                       ║
  20. //   ║                                                                    ║
  21. //   ║  This software is provided as is and carries no warranty           ║
  22. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  23. //   ║  warranties of merchantability, title and fitness for a particular ║
  24. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  25. //   ║  your requirements or that the software is without defect or error ║
  26. //   ║  or that operation of the software will be uninterrupted.  You are ║
  27. //   ║  using the software at your risk.  The software is not a product   ║
  28. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  29. //   ║                                                                    ║
  30. //   ╚════════════════════════════════════════════════════════════════════╝
  31. //
  32. //                         ****** N O T I C E ******
  33. //
  34. //     This software is considered pre-release and may be used at your own
  35. //     risk and has been provided due to the many requests of our cust-
  36. //     omers.  Support for this module will be provided at the sole
  37. //     discretion of Novell, Inc.
  38. //
  39.  
  40. #include <stdio.h>
  41. #include <string.h>
  42. #include <dos.h>
  43. #include <dir.h>
  44.  
  45. #include "nwsys.c"
  46.  
  47. struct REQUEST {
  48.     WORD sfLen;        // length of the structure
  49.     BYTE sfCode;       // subfunction code
  50.     BYTE volNumber;    // volume number
  51.     WORD sequence;     // last sequence number
  52.     LONG objectID;     // bindery object ID
  53. } request;
  54.  
  55. struct REPLY {
  56.     WORD sequence;     // next sequence number
  57.     LONG objectID;     // bindery object ID
  58.     BYTE accessMask;   // trustee access mask
  59.     BYTE pathLength;   // length of directory path
  60.     BYTE path[255];    // directory path
  61. } reply;
  62.  
  63. struct VOL_REQ {
  64.     WORD sfLen;
  65.     BYTE sfCode;
  66.     BYTE nameLen;
  67.     BYTE name[16];
  68. } volNumReq;
  69.  
  70. struct VOL_REP {
  71.     WORD repLength;
  72.     BYTE volNumber;
  73. } volNumRep;
  74.  
  75. struct BIND_REQUEST {
  76.     WORD  sfLen;            // length of the structure
  77.     BYTE  sfCode;           // subfunction code
  78.     WORD  objectType;       // bindery object type
  79.     BYTE  objectNameLength; // name length: 1 to 47
  80.     BYTE  objectName[48];   // bindery object name
  81. } binderyRequest;
  82.  
  83. struct BIND_REPLY {
  84.     WORD  replyLen;         // length of reply buffer
  85.     DWORD objectID;         // bindery object ID
  86.     WORD  objectType;       // bindery object type
  87.     BYTE  objectName[48];   // bindery object name
  88. } binderyReply;
  89.  
  90. WORD NWSystemCall2(BYTE func,             // function code
  91.                      void far *req,         // request buffer
  92.                    void far *rep)         // reply buffer
  93. {
  94.     union   REGS    regs;
  95.     struct  SREGS   sregs;
  96.  
  97.     segread(&sregs);
  98.  
  99.     memset(®s, 0, sizeof(regs));
  100.  
  101.     regs.h.ah = func;               // AH = function code
  102.     regs.x.si = FP_OFF(req);        // SI = request buffer offset
  103.     regs.x.di = FP_OFF(rep);        // DI = reply buffer offset
  104.  
  105.     sregs.ds = FP_SEG(req);         // DS = request buffer segment
  106.     sregs.es = FP_SEG(rep);         // ES = reply buffer segment
  107.  
  108.     intdosx(®s,®s,&sregs);    // do the Int 21
  109.  
  110.     return (WORD)regs.h.al;         // return code is in AL
  111. }
  112.  
  113. BYTE GetVolumeNumber(char *volName)
  114. {
  115.     int retCode;
  116.  
  117.     volNumReq.sfCode = 0x05;
  118.     volNumReq.nameLen = (BYTE) strlen(volName);
  119.     memmove((char *) &(volNumReq.name), volName, volNumReq.nameLen);
  120.     volNumReq.sfLen = volNumReq.nameLen + 2;
  121.  
  122.     retCode = NWSystemCall2(0xe2, &volNumReq, &volNumRep);
  123.     if (retCode) {
  124.         printf("Get Volume Number failed.  Return code = %d.\n", retCode);
  125.         return(255);
  126.     }
  127.     else
  128.         return(volNumRep.volNumber);
  129. }
  130.  
  131. WORD GetBinderyObjectID(char *userName, WORD objectType, DWORD *objectID)
  132. {
  133.     int retCode;
  134.  
  135.     binderyRequest.sfLen = sizeof(binderyRequest);
  136.     binderyRequest.sfCode = 0x35;
  137.     binderyRequest.objectType = WordSwap(objectType);
  138.     binderyRequest.objectNameLength = strlen(userName);
  139.     strcpy((char *) &(binderyRequest.objectName), userName);
  140.     binderyReply.replyLen = sizeof(binderyReply);
  141.  
  142.     retCode = NWSystemCall2(0xe3, &binderyRequest, &binderyReply);
  143.     *objectID = binderyReply.objectID;
  144.     return(retCode);
  145. }
  146.  
  147. int main()
  148. {
  149.     int i, retCode, diskNumber;
  150.     WORD serverConnectionID, objectType;
  151.     DWORD objectID;
  152.     BYTE volNumber;
  153.     char name[80];
  154.  
  155.     printf("Volume name: ");
  156.     gets(name);
  157.  
  158.     volNumber = GetVolumeNumber(name);
  159.  
  160.     if (volNumber == 255)
  161.         return(1);
  162.  
  163.     printf("User name: ");
  164.     gets(name);
  165.     objectType = 1; /* OT_USER */
  166.  
  167.     retCode = GetBinderyObjectID(name, objectType, &objectID);
  168.     if (retCode != 0) {
  169.         printf("Get Bindery Object ID failed.  Return code = %d.\n", retCode);
  170.         return(1);
  171.     }
  172.  
  173.     request.sfLen = sizeof(request);
  174.     request.sfCode = 0x47;
  175.     request.volNumber = volNumber;
  176.     request.sequence = -1L;
  177.     request.objectID = objectID;
  178.     retCode = NWSystemCall(0x17, &request, sizeof(request),
  179.                                  &reply,   sizeof(reply));
  180.     if (retCode == 0) 
  181.         printf("%s    Access Mask:\n", reply.path, reply.accessMask);
  182.     else {
  183.         printf("Scan Bindery Object Trustee Paths failed.  Return code = %d.\n",
  184.             retCode);
  185.         return(1);
  186.     }
  187.     return(0);
  188. }
  189.